package com.goods.controller.business;


import com.goods.business.service.InStockService;
import com.goods.common.response.ResponseBean;
import com.goods.common.vo.business.InStockDetailVO;
import com.goods.common.vo.business.InStockVO;
import com.goods.common.vo.system.PageVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/business/inStock")
public class InStockController {

    @Autowired
    private InStockService inStockService;

    //入库单（入库记录）数据分页列表展示
    @GetMapping("/findInStockList")
    public ResponseBean<PageVO<InStockVO>> findInStockList(@RequestParam(defaultValue = "1") Integer pageNum,
                                                           @RequestParam(defaultValue = "10") Integer pageSize,
                                                           Integer status,
                                                           Integer type,
                                                           String inNum,
                                                           String startTime,
                                                           String endTime){

        PageVO<InStockVO> pageVO = inStockService.findInStockList(pageNum,pageSize,status,type,inNum,startTime,endTime);
        return ResponseBean.success(pageVO);
    }

    //查看入库单明细
    @GetMapping("/detail/{id}")
    public ResponseBean detailInStock(@PathVariable Long id,
                                      @RequestParam(defaultValue = "1") Integer pageNum,
                                      @RequestParam(defaultValue = "3") Integer pageSize){
        InStockDetailVO inStockDetailVO = inStockService.detailInStock(id,pageNum,pageSize);
        return ResponseBean.success(inStockDetailVO);
    }

    //将入库单移入回收站
    @PutMapping("/remove/{id}")
    public ResponseBean removeInStock(@PathVariable Long id){
        inStockService.removeInStock(id);
        return ResponseBean.success();
    }

    //将回收状态入库单还原
    @PutMapping("/back/{id}")
    public ResponseBean backInStock(@PathVariable Long id){
        inStockService.backInStock(id);
        return ResponseBean.success();
    }

    //删除入库单
    @GetMapping("/delete/{id}")
    public ResponseBean deleteStock(@PathVariable Long id){
        inStockService.deleteStock(id);
        return ResponseBean.success();
    }

    //添加入库单
    @PostMapping("/addIntoStock")
    public ResponseBean addInStock(@RequestBody Map<String,Object> map){
        inStockService.addInStock(map);
        return ResponseBean.success();
    }

    //入库单审核
    @PutMapping("/publish/{id}")
    public ResponseBean publishInStock(@PathVariable Long id){
        //更新入库单状态
        inStockService.publishInStock(id);
        //更新库存数量
        inStockService.addProductStock(id);
        return ResponseBean.success();
    }
}
